﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Texfina.BOQry.Co;
using Texfina.Core.Common;
using Texfina.Core.Web;
using Texfina.Entity.Co;

namespace CO
{
    public partial class WfExportacion : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsCallback) return;

            if (!Page.IsPostBack)
            {
                LoadData();
              
            }
        }
        //public void RefreshLoadNumbers()
        //{
        //    AddCallbackControl(dpEmbarque);
        //    AddCallbackControl(dpTipTerminos);
        //}

        private void LoadData()
        {
            btnNuevo.ImageUrl = Constants2.ConstMenuControlValue.BUTTON_NEW;
            btnGrabar.ImageUrl = Constants2.ConstMenuControlValue.BUTTON_SAVENEW;
            btnSalir.ImageUrl = Constants2.ConstMenuControlValue.BUTTON_EXIT;
            WebHelper.LoadListControl2(dpTipTerminos, BTablaGeneral.TablaGeneralFill("135"), "ds_item", "id_item");
            WebHelper.LoadListControl2(dpEmbarque, BTablaGeneral.TablaGeneralFill("134"), "ds_item", "id_item");
        }
        protected void btnExporta_Click(object sender, EventArgs e)
        {
            try
            {
                Session[Constants2.ConstSessionVar.SESION_EXPORTACION] = "__SESION_EXPORTACION";
                ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'wfExportaciones.aspx', null, 'height=400,width=700,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);

            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }

        protected void btnNuevo_Click(object sender, ImageClickEventArgs e)
        {
            txtCodigo.Text = "";
            txtDescrip.Text = "";
        }

        protected void btnGrabar_Click(object sender, ImageClickEventArgs e)
        {
            Eexportacion prov = new Eexportacion();

            DropDownList idImp = new DropDownList();
            if (txtCodigo.Text == "")
            {
                WebHelper.LoadListControl2(idImp, BExportacion.Exportacion_qry01(Session[ConstSessionVar.PERIODO].ToString(), Session[ConstSessionVar.EMPRESA].ToString()), "id_Exportacion", "id_Exportacion");
                hddExportacion.Value = idImp.SelectedItem.Text;
                prov.Id_Exporta = hddExportacion.Value;
                prov.Id_Empresa = Session[ConstSessionVar.EMPRESA].ToString();
            }
            else
            {
                prov.Id_Exporta = txtCodigo.Text;
                prov.Id_Empresa = Session[ConstSessionVar.EMPRESA].ToString();
            }
            prov.Ds_Exporta = txtDescrip.Text.ToUpper();
            prov.Id_via = dpEmbarque.SelectedValue;
            prov.Id_tercom = dpTipTerminos.SelectedValue;
            prov.Id_ucrearec = Session[ConstSessionVar.IDLOGON].ToString();
            prov.Id_uupdarec = Session[ConstSessionVar.IDLOGON].ToString();
            BExportacion.Exportacion_mnt01(prov);

            lblMensaje.Text = "Datos Grabados";
            txtCodigo.Text = hddIdimportacion.Value;
        }
    }
}